package edu.henu.personnel.config;

import edu.henu.personnel.component.LoginHandlerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * @program: PersonnelProject
 * @description:
 * @author: zhuyang
 * @create: 2019-05-10 17:05
 */


@Configuration
public class MyMvcConfig extends WebMvcConfigurerAdapter {
    @Bean
    public WebMvcConfigurerAdapter webMvcConfigurerAdapter() {
        WebMvcConfigurerAdapter adapter = new WebMvcConfigurerAdapter() {
            @Override
            public void addViewControllers(ViewControllerRegistry registry) {
                registry.addViewController("/").setViewName("index");
                registry.addViewController("/index.html").setViewName("index");
                registry.addViewController("/dashboard.html").setViewName("dashboard");
                registry.addViewController("/bodyIndex.html").setViewName("bodyIndex");
                registry.addViewController("/form.html").setViewName("form");
                registry.addViewController("/notice/list.html").setViewName("./notice/list");
                registry.addViewController("/notice/modify.html").setViewName("./notice/modify");
                registry.addViewController("/second/jgsz.html").setViewName("/second/jgsz");
                registry.addViewController("/second/gzzz.html").setViewName("/second/gzzz");
                registry.addViewController("/common/building.html").setViewName("/common/building");
            }

            @Override
            public void addInterceptors(InterceptorRegistry registry) {
                registry.addInterceptor(new LoginHandlerInterceptor()).addPathPatterns("/**")
                        .excludePathPatterns("/index.html", "index", "/", "/login", "/login.html",
                                "/display/**", "/display.html", "/error/**", "/teachers.html", "/teachers",
                                "/second/jgsz", "/second/jgsz.html", "/second/gzzz", "/second/gzzz.html",
                                "/common/building", "/common/building.html");
            }
        };
        return adapter;
    }
}
